﻿using System;
using System.Windows.Forms;
using MobileCarManager.MobileControls.Styles;
using System.Globalization;
namespace MobileCarManager.MobileControls.AppStylist.Stylists.Button
{
  public partial class ButtonStylist : UserControl
  {
    public ButtonStylist()
    {
      InitializeComponent();

      pictureBoxBorderColor.BackColor = StyleManager.Instance.Styles.Button.Border.Color;
      textBoxBorderWidth.Text = StyleManager.Instance.Styles.Button.Border.Width.ToString(CultureInfo.CurrentUICulture);
      pictureBoxBackcolor1.BackColor = StyleManager.Instance.Styles.Button.BackgroundGradient.Gradient[0];
      pictureBoxBackcolor2.BackColor = StyleManager.Instance.Styles.Button.BackgroundGradient.Gradient[1];
      pictureBoxBackcolor3.BackColor = StyleManager.Instance.Styles.Button.BackgroundGradient.Gradient[2];
      pictureBoxFontColor.BackColor = StyleManager.Instance.Styles.Button.TextColor;
    }

    private void OnBorderColorClick(object sender, EventArgs e)
    {
      colorDialog.Color = pictureBoxBorderColor.BackColor;
      if (DialogResult.OK == colorDialog.ShowDialog())
      {
        pictureBoxBorderColor.BackColor = colorDialog.Color;
        StyleManager.Instance.Styles.Button.Border.Color = colorDialog.Color;
        styleButton1.Invalidate();
      }
    }

    private void OnLeaveBorderWidth(object sender, EventArgs e)
    {
      int borderWidth = StyleManager.Instance.Styles.Button.Border.Width;
      if (int.TryParse(textBoxBorderWidth.Text, NumberStyles.Integer, CultureInfo.CurrentUICulture, out borderWidth))
      {
        StyleManager.Instance.Styles.Button.Border.Width = borderWidth;
        styleButton1.Invalidate();
      }
      else
      {
        textBoxBorderWidth.Text = borderWidth.ToString(CultureInfo.CurrentUICulture);
      }
    }

    private void OnBackcolor1Click(object sender, EventArgs e)
    {
      colorDialog.Color = pictureBoxBackcolor1.BackColor;
      if (DialogResult.OK == colorDialog.ShowDialog())
      {
        pictureBoxBackcolor1.BackColor = colorDialog.Color;
        StyleManager.Instance.Styles.Button.BackgroundGradient.Gradient[0] = colorDialog.Color;
        styleButton1.Invalidate();
      }
    }

    private void OnBackcolor2Click(object sender, EventArgs e)
    {
      colorDialog.Color = pictureBoxBackcolor2.BackColor;
      if (DialogResult.OK == colorDialog.ShowDialog())
      {
        pictureBoxBackcolor2.BackColor = colorDialog.Color;
        StyleManager.Instance.Styles.Button.BackgroundGradient.Gradient[1] = colorDialog.Color;
        styleButton1.Invalidate();
      }
    }

    private void OnBackcolor3Click(object sender, EventArgs e)
    {
      colorDialog.Color = pictureBoxBackcolor3.BackColor;
      if (DialogResult.OK == colorDialog.ShowDialog())
      {
        pictureBoxBackcolor3.BackColor = colorDialog.Color;
        StyleManager.Instance.Styles.Button.BackgroundGradient.Gradient[2] = colorDialog.Color;
        styleButton1.Invalidate();
      }
    }

    private void OnFontColorClick(object sender, EventArgs e)
    {
      colorDialog.Color = pictureBoxFontColor.BackColor;
      if (DialogResult.OK == colorDialog.ShowDialog())
      {
        pictureBoxFontColor.BackColor = colorDialog.Color;
        StyleManager.Instance.Styles.Button.TextColor = colorDialog.Color;
        styleButton1.Invalidate();
      }
    }

    private void buttonFont_Click(object sender, EventArgs e)
    {
      FontDialog dlg = new FontDialog();
      dlg.Font = StyleManager.Instance.Styles.Button.Font;
      if (DialogResult.OK == dlg.ShowDialog())
      {
        StyleManager.Instance.Styles.Button.Font = dlg.Font;
        styleButton1.Invalidate();
      }
    }
  }
}
